package controller;

import pojo.Goods;
import service.IGoodsService;
import service.impl.GoodsServiceImpl;
import utils.NoLoginUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "DetailServlet", value = "/detail")
public class DetailServlet extends HttpServlet {
    private IGoodsService goodsService;

    @Override
    public void init() throws ServletException {
        goodsService = new GoodsServiceImpl();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        NoLoginUtil.doVerify(request);
        int goodsId = Integer.parseInt(request.getParameter("goods-id"));
        Goods aGoods = goodsService.queryGoodsById(goodsId);
        request.setAttribute("aGoods", aGoods);
        request.getRequestDispatcher("/WEB-INF/detail.jsp").forward(request, response);
    }
}
